<template>
  <MainPage>
    <template v-slot:HeaderLeft>
      <el-form
        :inline="true"
        :model="form"
        class="demo-form-inline"
        ref="userListFrom"
        label-width="70px"
      >
        <el-form-item label="菜品名称" prop="name">
          <el-input
            v-model.trim="form.name"
            placeholder="菜品名称"
            clearable
            class="wid220"
          ></el-input>
        </el-form-item>
        <el-form-item label="规模" prop="scale">
          <el-select
            v-model.trim="form.scale"
            placeholder="规模"
            class="wid220"
          >
            <el-option label="所有" value=""></el-option>
            <el-option
              v-for="(scale, index) in scale_list"
              :key="index"
              :label="scale"
              :value="parseInt(index) + 1"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="联系人" prop="contact">
          <el-input
            v-model.trim="form.contact"
            placeholder="联系人/手机"
            clearable
            class="wid220"
          ></el-input>
        </el-form-item>
        <el-form-item label="提交时间" prop="sendTime">
          <el-date-picker
            v-model="sendTime"
            type="daterange"
            class="time220"
            :editable="false"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            :clearable="false"
            :picker-options="dateOption"
          />
        </el-form-item>

        <div class="clearfix"></div>
        <el-form-item class="marginTop5">
          <el-button class="reset marginLeft10" type="primary" @click="reset"
            >重置</el-button
          >
          <el-button type="primary" @click="getArticleList" :loading="loading"
            >搜索</el-button
          >
        </el-form-item>
      </el-form></template
    >

    <template v-slot:Table>
      <el-table
        ref="multipleTable"
        v-loading="loading"
        :data="list"
        element-loading-text="加载中"
        fit
        border
        highlight-current-row
        :header-cell-class-name="verticaline"
      >
        <el-table-column
          label="菜品名称"
          show-overflow-tooltip
          prop=""
          min-width="90"
        >
          <template slot-scope="scope"
            ><span>
              {{ scope.row.dishes_name }}
            </span></template
          >
        </el-table-column>
        <el-table-column
          label="规模大小"
          show-overflow-tooltip
          prop=""
          min-width="90"
        >
          <template slot-scope="scope">
            <span :style="{ color: scope.row.scale ? '#03A98E' : '#F56C6C' }">
              {{ scale_list[scope.row.scale] }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="图片" prop="" width="200">
          <template slot-scope="scope"
            ><div class="image">
              <el-image :src="scope.row.imgs[0]">
                <div slot="error" class="image-slot">
                  <img :src="puzzleImg" />
                </div>
              </el-image></div
          ></template>
        </el-table-column>
        <el-table-column
          label="供应量"
          min-width="90"
          show-overflow-tooltip
          prop="supply_num"
        >
        </el-table-column>
        <el-table-column
          label="报价"
          min-width="90"
          show-overflow-tooltip
          prop="offer"
        >
        </el-table-column>
        <el-table-column
          label="供应日期"
          min-width="90"
          show-overflow-tooltip
          prop=""
        >
          <template slot-scope="scope"
            ><span>
              {{
                scope.row.supply_time
                  ? parseTime(scope.row.supply_time, "{y}-{m}-{d}")
                  : ""
              }}
            </span></template
          >
        </el-table-column>
        <el-table-column
          label="供应方式"
          min-width="90"
          show-overflow-tooltip
          prop=""
        >
          <template slot-scope="scope">
            <span
              :style="{ color: scope.row.supply_type ? '#03A98E' : '#F56C6C' }"
            >
              {{ supply_list[scope.row.supply_type] }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="提交时间" min-width="150" prop="">
          <template slot-scope="scope"
            ><span>
              {{ scope.row.created_at ? parseTime(scope.row.created_at) : "" }}
            </span></template
          >
        </el-table-column>
        <el-table-column
          label="管理操作"
          align="left"
          fixed="right"
          width="200"
          class-name="main_hei"
        >
          <template slot-scope="scope">
            <el-link type="success" @click="local_info(scope.row.id)"
              >查看</el-link
            >
          </template>
        </el-table-column>
      </el-table></template
    >
    <template v-slot:Page>
      <el-pagination
        :current-page="current.page"
        :page-sizes="[20, 30, 50, 100]"
        :page-size="limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
        background
        @size-change="changeLimit"
        @current-change="changePage"
    /></template>
    <template v-slot:Dialog>
      <el-dialog title="菜品详情" :visible.sync="dialogVisible" class="dialog">
        <div class="dialog_continer">
          <li>
            <span>菜品名称：</span> <span>{{ info.dishes_name }}</span>
          </li>
          <li>
            <span>规模：</span> <span>{{ scale_list[info.scale] }}</span>
          </li>
          <li>
            <span>供应量：</span> <span>{{ info.supply_num }}</span>
          </li>
          <li>
            <span>报价：</span>
            <span>{{ info.offer }}</span>
          </li>
          <li>
            <span>供应日期：</span
            ><span>
              {{
                info.supply_time
                  ? parseTime(info.supply_time, "{y}-{m}-{d}")
                  : ""
              }}</span
            >
          </li>
          <li>
            <span>供应方式：</span
            ><span>{{ supply_list[info.supply_type] }}</span>
          </li>
          <li class="main">
            <span> 图片：</span>
            <div class="img_div">
              <el-image
                v-for="(item, key) in info.imgs"
                :key="key"
                :src="item"
                :preview-src-list="info.imgs"
              >
                <div slot="error" class="image-slot">
                  <img :src="puzzleImg" />
                </div>
              </el-image>
            </div>
          </li>
          <li class="main">
            <span>简介：</span>
            <span>{{ info.introduction }}</span>
          </li>
          <li>
            <span>联系人：</span> <span>{{ info.contacts }}</span>
          </li>
          <li>
            <span>手机号：</span> <span>{{ info.mobile }}</span>
          </li>
          <li class="main">
            <span>联系地址：</span><span>{{ info.address }}</span>
          </li>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">关闭</el-button>
        </span>
      </el-dialog>
    </template>
  </MainPage>
</template>
<script>
import MainPage from "@/components/MainPage";
import { parseTime } from "@/utils/index";
import { puzzleImg } from "@/api/currency";
import dateOption from "@/options/dateOption";
import { mapGetters } from "vuex";
import {
  local_index,
  local_info,
} from "@/api/purchasing/purchasingLocalVegetable";
export default {
  components: {
    MainPage,
  },
  computed: {
    ...mapGetters(["avatar"]),
  },
  data() {
    return {
      verticaline: this.$verticaline,
      parseTime,
      puzzleImg,
      dateOption,
      form: {
        name: "",
        contact: "",
        start_time: "",
        end_time: "",
      },
      sendTime: [],
      list: [],
      scale_list: [],
      supply_list: [],
      info: {},
      // 分页
      current: {
        page: 1,
        per_page: 20,
      },
      limit: 20,
      totalCount: 1,
      loading: false,
      dialogVisible: false,
    };
  },
  methods: {
    getArticleList() {
      this.current.page = 1;
      this.local_index();
    },
    reset() {
      this.$refs["userListFrom"].resetFields();
      this.sendTime = [];
      this.getArticleList();
    },
    changeLimit(pageSize) {
      this.current.per_page = pageSize;
      this.local_index();
    },
    changePage(page) {
      this.current.page = page;
      this.local_index();
    },
    local_index() {
      this.loading = true;
      this.form.start_time = this.sendTime ? this.sendTime[0] : "";
      this.form.end_time = this.sendTime ? this.sendTime[1] : "";
      let data = Object.assign({}, this.form, this.current);

      local_index(data).then((res) => {
        if (res.errcode == 0) {
          this.scale_list = res.data.scale_list;
          this.supply_list = res.data.supply_list;
          this.totalCount = res.data.list.total;
          res.data.list.data.map((e) => {
            e.imgs = [];
            if (e.img) {
              let imgs = e.img.split(",");
              e.imgs = imgs.map((e) => {
                return this.avatar.domain + e;
              });
            }
          });
          this.list = res.data.list.data;
        } else {
          this.$message.error(res.errmsg);
        }
        this.loading = false;
      });
    },
    local_info(id) {
      let data = { id: id };
      local_info(data).then((res) => {
        if (res.errcode == 0) {
          let imgs = res.data.info.img.split(",");
          res.data.info.imgs = imgs.map((e) => {
            return this.avatar.domain + e;
          });
          this.info = res.data.info;
          this.dialogVisible = true;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
  },
  created() {
    this.local_index();
  },
};
</script>
<style lang='scss' scoped>
/deep/ .main_table .el-table--small td .cell {
  height: auto;
}
.image {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-center;
}
/deep/ .el-dialog__body {
  padding: 20px 40px;
  .el-image {
    margin-right: 15px;
    img {
      max-width: 200px;
      max-height: 200px;
    }
  }
}
>>> .dialog .el-dialog {
  width: 750px;
}
>>> .el-table__row .el-image img {
  max-width: 100px;
  max-height: 100px;
}
.dialog_continer {
  display: flex;
  align-items: flex-start;
  justify-content: space-around;
  flex-wrap: wrap;
  li {
    width: 50%;
    font-size: 16px;
    line-height: 40px;
    display: flex;
    align-items: flex-start;
    font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB,
      Microsoft YaHei, SimSun, sans-serif;

    span:first-child {
      flex-grow: 0;
      flex-basis: 1;
      flex-shrink: 0;
      width: 80px;
      text-align: right;
    }
    span:last-child {
      margin-left: 15px;
      font-size: 16px;
      vertical-align: bottom;
    }
    &.main {
      width: 100%;
    }
    .img_div {
      display: flex;
      align-items: center;
      margin-left: 15px;
      >>> .image-slot {
        display: flex;
        align-items: center;
      }
    }
  }
}
</style>
